package demo13;

/**
 * @program: qy158
 * @description:
 * @author: 闫克起2
 * @create: 2022-11-01 09:14
 **/
public class TestYield {
    public static void main(String[] args) {
        YieldDemo t1=new YieldDemo();
        YieldDemo t2=new YieldDemo();
        t1.start();
        t2.start();
    }
}
class YieldDemo extends Thread{
    @Override
    public void run() {
        for (int i = 0; i <20 ; i++) {
            //当前线程放弃时间片，进入就绪状态，参与下次cpu时间片的竞争。 可能出现交替的频率比较高
            Thread.yield();
            System.out.println(Thread.currentThread().getName()+"~~~~~~~~~~"+i);
        }
    }
}
